package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.card.EntityXfShoppingCart;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.GetDishesFormCartRequest;
import com.ocom.common.request.payconfig.RemoveDishesToCartRequest;
import com.ocom.common.request.payconfig.RollbackDishesCartRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.XfShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.ocom.common.request.payconfig.SubmitDishesCartRequest;

@Slf4j
@RestController
public class XfShoppingCartController {

    @Autowired
    private XfShoppingCartService xfShoppingCartService;

    @PostMapping(PayConfigUrl.URL_addDishesToCart)
    public Result addDishesToCart(@RequestBody EntityXfShoppingCart xfShoppingCart){
        return this.xfShoppingCartService.addDishesToCart(xfShoppingCart, xfShoppingCart.getComId());
    }

    @PostMapping(PayConfigUrl.URL_removeDishesToCart)
    public Result removeDishesToCart(@RequestBody RemoveDishesToCartRequest request){
        this.xfShoppingCartService.removeDishesToCart(request, request.getComId());
        return ResultUtil.success();
    }

    @PostMapping(PayConfigUrl.URL_getDishesFormCart)
    public Result getDishesFormCart(@RequestBody GetDishesFormCartRequest request){
        return ResultUtil.success(this.xfShoppingCartService.getDishesFormCart(request, request.getComId()));
    }

    @PostMapping(PayConfigUrl.URL_submitDishesCart)
    public Result submitDishesCart(@RequestBody SubmitDishesCartRequest request){
        this.xfShoppingCartService.submitDishesCart(request, request.getComId());
        return ResultUtil.success();
    }

    @PostMapping(PayConfigUrl.URL_rollbackDishesCart)
    public Result rollbackDishesCart(@RequestBody RollbackDishesCartRequest request){
        this.xfShoppingCartService.rollbackDishesCart(request, request.getComId());
        return ResultUtil.success();
    }
}
